using System;
using ch.ethz.ssh2.sftp;
namespace ch.ethz.ssh2
{
	
	/// <summary> Used in combination with the SFTPv3Client. This exception wraps
	/// error messages sent by the SFTP server.
	/// 
	/// </summary>
	/// <author>  Christian Plattner
	/// </author>
	/// <version>  2.50, 03/15/10
	/// </version>
	
	[Serializable]
	public class SFTPException:System.IO.IOException
	{
		/// <summary> Get the error message sent by the server. Often, this
		/// message does not help a lot (e.g., "failure").
		/// 
		/// </summary>
		/// <returns> the plain string as sent by the server.
		/// </returns>
		virtual public System.String ServerErrorMessage
		{
			get
			{
				return sftpErrorMessage;
			}
			
		}
		/// <summary> Get the error code sent by the server.
		/// 
		/// </summary>
		/// <returns> an error code as defined in the SFTP specs.
		/// </returns>
		virtual public int ServerErrorCode
		{
			get
			{
				return sftpErrorCode;
			}
			
		}
		/// <summary> Get the symbolic name of the error code as given in the SFTP specs.
		/// 
		/// </summary>
		/// <returns> e.g., "SSH_FX_INVALID_FILENAME".
		/// </returns>
		virtual public System.String ServerErrorCodeSymbol
		{
			get
			{
				System.String[] detail = ErrorCodes.getDescription(sftpErrorCode);
				
				if (detail == null)
					return "UNKNOW SFTP ERROR CODE " + sftpErrorCode;
				
				return detail[0];
			}
			
		}
		/// <summary> Get the description of the error code as given in the SFTP specs.
		/// 
		/// </summary>
		/// <returns> e.g., "The filename is not valid."
		/// </returns>
		virtual public System.String ServerErrorCodeVerbose
		{
			get
			{
				System.String[] detail = ErrorCodes.getDescription(sftpErrorCode);
				
				if (detail == null)
					return "The error code " + sftpErrorCode + " is unknown.";
				
				return detail[1];
			}
			
		}
		private const long serialVersionUID = 578654644222421811L;
		
		//UPGRADE_NOTE: Final was removed from the declaration of 'sftpErrorMessage '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
		private System.String sftpErrorMessage;
		//UPGRADE_NOTE: Final was removed from the declaration of 'sftpErrorCode '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
		private int sftpErrorCode;
		
		private static System.String constructMessage(System.String s, int errorCode)
		{
			System.String[] detail = ErrorCodes.getDescription(errorCode);
			
			if (detail == null)
				return s + " (UNKNOW SFTP ERROR CODE)";
			
			return s + " (" + detail[0] + ": " + detail[1] + ")";
		}
		
		internal SFTPException(System.String msg, int errorCode):base(constructMessage(msg, errorCode))
		{
			sftpErrorMessage = msg;
			sftpErrorCode = errorCode;
		}
	}
}